package hongcaosp.app.android.redpacket;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import hongcaosp.app.android.R;

public class RedPacketOpenDialog extends Dialog {

    private ImageView moneyIV;
    private TextView moneyTV;
    private String text;
    private int type;

    private boolean dimissDetail;

    public void setText(String text,int type) {
        this.text = text;
        this.type = type;
    }

    public void setDimissDetail(boolean dimissDetail) {
        this.dimissDetail = dimissDetail;
    }

    public RedPacketOpenDialog(@NonNull Context context) {
        super(context,R.style.MoneyDialog);
    }

    public RedPacketOpenDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected RedPacketOpenDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setGravity(Gravity.CENTER);
        getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);

        setContentView(R.layout.dialog_redpacket_open);
        setCanceledOnTouchOutside(false);

        if (dimissDetail) {
            findViewById(R.id.des_tv).setVisibility(View.GONE);
        }
        moneyIV = findViewById(R.id.money_icon);
        moneyTV = findViewById(R.id.money_tv);
        if (type == -1) {
            findViewById(R.id.des_tv).setVisibility(View.GONE);
            moneyTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
        }
        moneyTV.setText(text);

        findViewById(R.id.close_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

}
